// src/store/index.js
import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    loading: false,
    token: localStorage.getItem('token') || ''
  },
  mutations: {
    setLoading(state, status) {
      state.loading = status;
    },
    setToken(state, token) {
      state.token = token;
      localStorage.setItem('token', token);
    },
    clearToken(state) {
      state.token = '';
      localStorage.removeItem('token');
    }
  },
  actions: {
    showLoading({ commit }) {
      commit('setLoading', true);
    },

    hideLoading({ commit }) {
      commit('setLoading', false);
    },

    saveToken({ commit }, token) {
      commit('setToken', token);
    },

    removeToken({ commit }) {
      commit('clearToken');
    }



  }
});